function combineNum(arr, target) {
    // 终止条件
    let res = []
    let path = []
    let used = {}
    let index = 0
    arr.sort((a, b) => {
        return a - b
    })

    function genCombineNum(num) {
        // 终止条件
        if (num === target) {
            res.push(path.slice())
            return path[path.length - 1]
        }
        if (num > target) {
            return
        }

        let tempUsed = {}
        for (let i = index; i < arr.length; i++) {
            const item = arr[i];
            if (used[i]) {
                continue
            }
            if (tempUsed[item]) {
                continue
            }
            used[i] = true
            tempUsed[item] = true
            path.push(item)
            index = i
            genCombineNum(num + item)
            path.pop()
            used[i] = false
        }
    }
    genCombineNum(0)
    return res
}

console.log(combineNum([2, 5, 2, 1, 2], 5))